package com.zhku.onlineshop.Service.impl;

import com.zhku.onlineshop.Dao.OrderDao;
import com.zhku.onlineshop.Dao.ProductDao;
import com.zhku.onlineshop.Pojo.Product;
import com.zhku.onlineshop.Pojo.User;
import com.zhku.onlineshop.Service.ProductService;
import com.zhku.onlineshop.dto.ProductRating;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ProductServiceimpl implements ProductService {
    @Autowired
   private ProductDao productDao;


    @Override
    public List<Product> GetProductsList() {
        return productDao.GetProductsList();
    }

    @Override
    public boolean AddProduct(Product product) {
        return productDao.AddProduct(product);
    }

    @Override
    public List<Product> GetProductById(Integer id) {
        return productDao.GetProductById(id);
    }

    @Override
    public boolean DelProductById(Integer id) {
        return productDao.DelProductById(id);
    }

    @Override
    public boolean UpdProduct(Product product) {
        return productDao.UpdProduct(product);
    }

    @Override
    public List<ProductRating> GetRattingById(Integer productId) {
        return productDao.GetRattingById(productId);
    }

    @Override
    public boolean AddRatting(ProductRating productRating) {
        return productDao.AddRatting(productRating);
    }

    @Override
    public List<Product> SelProduct() {
        List<Integer> ids = productDao.selectTopTenProductIds();
        String idString = ids.stream()
                .map(String::valueOf)
                .collect(Collectors.joining(","));
       return productDao.selectProductsByIds(idString);
    }
}
